package com.example.azheng.rxjavamvpdemo.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.azheng.rxjavamvpdemo.R;
import com.example.azheng.rxjavamvpdemo.bean.rechargelist.RechargeResponseData;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Time:2020/4/14
 * Author:ypf
 * Description:聊天室适配器
 */
public class RechargeListAdapter extends RecyclerView.Adapter<RechargeListAdapter.RecyclerHolder> {


    private Context mContext;
    private List<RechargeResponseData> mData;

    private OnItemClickListener mOnItemClickListener;

    public interface OnItemClickListener {
        void click(int position);
    }

    public void setmOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public RechargeListAdapter(Context context, List<RechargeResponseData> data) {
        this.mContext = context;
        this.mData = data;
    }

    @Override
    public RecyclerHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_recharge_record, parent, false);
        return new RecyclerHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerHolder holder, int position) {
        RechargeResponseData rechargeResponseData = mData.get(position);
        if (null == rechargeResponseData) {
            return;
        }
        int id = rechargeResponseData.getId();
        holder.tvId.setText("订单号：" + id);
        String status = rechargeResponseData.getStatus();
        if (!TextUtils.isEmpty(status)) {
            holder.tvStatus.setText(status);
        }
        String type = rechargeResponseData.getType();
        if (!TextUtils.isEmpty(type)) {
            holder.tvType.setText(type);
        }
        String money = rechargeResponseData.getMoney();
        if (!TextUtils.isEmpty(money)) {
            holder.tvMoney.setText(money);
        }
        int createtime = rechargeResponseData.getCreatetime();
        holder.tvCreateTime.setText(createtime + "");
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class RecyclerHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tvId)
        TextView tvId;
        @BindView(R.id.tvType)
        TextView tvType;
        @BindView(R.id.tvCreateTime)
        TextView tvCreateTime;
        @BindView(R.id.tvStatus)
        TextView tvStatus;
        @BindView(R.id.textView26)
        TextView textView26;
        @BindView(R.id.tvMoney)
        TextView tvMoney;

        RecyclerHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }
}
